Extract TitleBuilder for PR title composition#14285
Conversation
common/lib/dependabot/pull_request_creator/message_builder/components/title_builder.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/group_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/group_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/group_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/group_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/group_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/single_update.rb
Outdated
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/strategies/single_update.rb
Outdated
Show resolved
Hide resolved
7b980a2 to
bd3e3b1
Compare
9cc56cb to
c90bf8f
Compare
There was a problem hiding this comment.
Pull request overview
This PR extracts PR title composition logic out of MessageBuilder into a new TitleBuilder helper so title prefixing/capitalization can be reused (notably by dependabot-api for multi-ecosystem combined PRs) while keeping MessageBuilder#pr_name behavior consistent.
Changes:
- Add
TitleBuilderto compose a final PR title from a base title plus either aPrNamePrefixer(updater path) or explicitcommit_message_options(API path). - Update
MessageBuilder#pr_nameto delegate title composition toTitleBuilder. - Add specs covering prefix, scope, dev prefix behavior, and multi-ecosystem base title generation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| common/lib/dependabot/pull_request_creator/message_builder/title_builder.rb | Introduces extracted title composition logic intended for reuse outside MessageBuilder. |
| common/lib/dependabot/pull_request_creator/message_builder.rb | Delegates pr_name formatting to TitleBuilder and requires the new helper. |
| common/spec/dependabot/pull_request_creator/message_builder/title_builder_spec.rb | Adds unit tests for the new TitleBuilder behavior. |
You can also share your feedback on Copilot code review. Take the survey.
common/lib/dependabot/pull_request_creator/message_builder/title_builder.rb
Show resolved
Hide resolved
common/spec/dependabot/pull_request_creator/message_builder/title_builder_spec.rb
Outdated
Show resolved
Hide resolved
c90bf8f to
c44f7c3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
You can also share your feedback on Copilot code review. Take the survey.
common/spec/dependabot/pull_request_creator/message_builder/title_builder_spec.rb
Show resolved
Hide resolved
common/lib/dependabot/pull_request_creator/message_builder/title_builder.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
| require "dependabot/pull_request_creator/pr_name_prefixer" | ||
| require "dependabot/pull_request_creator/message_builder/title_builder" | ||
|
|
||
| RSpec.describe Dependabot::PullRequestCreator::MessageBuilder::TitleBuilder do | ||
| before do | ||
| Dependabot::Dependency.register_production_check( | ||
| "npm_and_yarn", | ||
| lambda do |groups| | ||
| return true if groups.empty? | ||
| return true if groups.include?("optionalDependencies") | ||
|
|
||
| groups.include?("dependencies") | ||
| end | ||
| ) | ||
| end | ||
|
|
There was a problem hiding this comment.
This spec registers a global production check for npm_and_yarn, which mutates Dependabot::Dependency state for the rest of the test suite (order-dependent) and duplicates the canonical lambda already defined in npm_and_yarn/lib/dependabot/npm_and_yarn.rb. Prefer requiring dependabot/npm_and_yarn to use the real registration, or avoid global registration by stubbing Dependency#production? / using test doubles for dependencies in these examples.
| require "dependabot/pull_request_creator/pr_name_prefixer" | |
| require "dependabot/pull_request_creator/message_builder/title_builder" | |
| RSpec.describe Dependabot::PullRequestCreator::MessageBuilder::TitleBuilder do | |
| before do | |
| Dependabot::Dependency.register_production_check( | |
| "npm_and_yarn", | |
| lambda do |groups| | |
| return true if groups.empty? | |
| return true if groups.include?("optionalDependencies") | |
| groups.include?("dependencies") | |
| end | |
| ) | |
| end | |
| require "dependabot/npm_and_yarn" | |
| require "dependabot/pull_request_creator/pr_name_prefixer" | |
| require "dependabot/pull_request_creator/message_builder/title_builder" | |
| RSpec.describe Dependabot::PullRequestCreator::MessageBuilder::TitleBuilder do |
|
|
||
| sig { returns(T::Boolean) } | ||
| def production_dependencies? | ||
| dependencies&.any?(&:production?) != false |
There was a problem hiding this comment.
production_dependencies? treats an empty dependencies array as non-production because [].any? is false (so the method returns false). Given dependencies is optional on this helper, callers may reasonably pass [] to mean “unknown/no deps”; in that case we likely want to default to production (or at least keep behavior consistent with nil, which currently defaults to production). Consider changing this to treat nil/empty as production (e.g., return true unless dependencies&.all? { |d| !d.production? }).
| dependencies&.any?(&:production?) != false | |
| return true if dependencies.nil? || dependencies.empty? | |
| dependencies.any?(&:production?) |
What are you trying to accomplish?
Extract a lightweight
TitleBuilderclass fromMessageBuilderso that PR title composition (prefix + capitalization + base title) can be reused bydependabot-apifor multi-ecosystem combined PRs.The current
MessageBuilderinlines prefix/capitalize logic inpr_name, which cannot be called fromdependabot-apiwithout instantiating the entire builder. The API currently hardcodes combined PR titles, completely bypassingcommit-messageprefix configuration — causing #14032 and #10057.Fixes #14032
Fixes #10057
Related: #12178
What changed?
1 new file —
common/lib/dependabot/pull_request_creator/message_builder/title_builder.rb:TitleBuilder#build— composes prefix + capitalization + base titlePrNamePrefixer(updater path) or lightweightcommit_message_optionshash (API path, no network calls)TitleBuilder.multi_ecosystem_base_title— class method for generating multi-ecosystem group titlesMessageBuilder#pr_namenow delegates toTitleBuilderinstead of inlining the prefix/capitalize logic. No feature flag — the change is a pure extraction with identical behavior.Anything you want to highlight for special attention from reviewers?
The change to
MessageBuilderis minimal (5 lines changed).TitleBuilderfollows the same pattern as existing helpers (IssueLinker,MetadataPresenter,LinkAndMentionSanitizer).The companion
dependabot-apiPR (github/dependabot-api#7792) usesTitleBuilderto fix the multi-ecosystem prefix bug.How will you know you have accomplished your goal?
TitleBuilderspec passes (10 examples covering prefix, capitalization, scope, dev dependencies, multi-ecosystem)MessageBuilderspecs continue to pass (behavior unchanged)dependabot-apicompanion PR can useTitleBuilderto applycommit-messageprefix to combined PRsChecklist